const util = require('../../utils/util.js');
const api = require('../../config/api.js');

const app = getApp();

Page({
  data: {
    list: [],
    page:1,
    totalPages:1,
  },
  onShareAppMessage() {
    return {};
  },
  onShow(){
    this.setData({
      list: [],
      totalPages: 1
    });
    this.getIndexData();
  },
  view_17OnClick(e){
    const id = e.currentTarget.dataset.id;
    if(id){
      wx.navigateTo({ url: '/pages/RemittanceAdd/RemittanceAdd?id='+id });
    }else{
      wx.showToast({
        title: 'id不存在',
        icon: 'error',
        duration: 600
      })
    }
  },
  view_4OnClick() {
    if(!this.data.list || this.data.list.length===0){
      wx.navigateTo({ url: '/pages/RemittanceAdd/RemittanceAdd' });
    }else{
      wx.showModal({
        content:'已有汇款信息，若需信息变更请编辑。',
        showCancel: false,//是否显示取消按钮
        confirmText:"确定",//默认是“确定”
        confirmColor: 'rgb(31, 103, 220)',//确定文字的颜色
        success: function (res) {
          if (res.confirm) {
            return false
          }
        },
      })
    }

  },
  getIndexData() {
    let that = this;
    util.request(api.RemittanceList,{pageRequestVo: {pageNum: this.data.page, pageSize: 10}},'POST').then(function(res) {
      if (res.errno === 200) {
        that.setData({
          list: that.data.list.concat(res.data.list || []),
          totalPages:res.data.pages
        });

      }
    });
  },
  onPullDownRefresh() {
    wx.stopPullDownRefresh() //停止下拉刷新
  },
  onReachBottom() {
    if ( this.data.page < this.data.totalPages ) {
      this.setData({
        page: this.data.page + 1
      });
      this.getIndexData();
    } else {
      wx.showToast({
        title: '没有更多了',
        icon: 'none',
        duration: 2000
      });
      return false;
    }
  },
});
